from django.shortcuts import render
from django.views import View

from apps.index.models import ContentCategory


class  IndexView(View):
    '''主页'''
    def get(self,request):
        # 查询商品频道和分类
        # categories_dict = get_categories()

        # 广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for temp in content_categories:
            contents[temp.key] = temp.content_set.filter(status=True).order_by('sequence')

        # 渲染模板的上下文
        context = {
            # 'categories': categories_dict,
            'contents': contents,
        }
        # for key,value in contents.items():
        #
        #     print(key,value)

        return render(request, 'index.html', context)
